<?php #20070710 

/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/*                                                                      */
/* upgrade application                                                  */
/************************************************************************/

global $source;
global $ver;


// questa rutine crea l'elenco dei file upgradabili
function get_source($path)
{
    global $ver;
    global $source;

    $dir = opendir($path);
    while($file = readdir($dir)){
	if(is_file($path."/".$file)){
	    $fh=@fopen($path."/".$file,"r");
	    $head=@fread($fh,1024);
	    $head=substr($head,6,strpos($head,"\n")-6);

	    @fclose($fh);
	    if ($head[0]=='#' && substr($head,1,4)!=0){
		$ver[$path."/".$file]= substr($head,1,8);
		$source[$path."/".$file]= substr($head,10);
	    }

	}
	if(is_dir($path."/".$file) && $file!="." && $file !=".."){
	    get_source($path."/".$file);
	}
    }
    closedir($dir);
}

echo "<h3 class='bartitle'>FrameWork Upgrade</h3>";

$op=$_GET['op'];

?>
	    <table style="font-size:9;" border='0'>
	    <tr>
	    <td>

        <fieldset ><br/>
	    <form name='selezupgrade' action='index.php?appname=<?=$appname;?>&op=tutto'  method='POST'>
		    <b>Seleziona: </b>	<input type='submit' value='tutto' />
	    </form>
	    </fieldset></td><td>

	    <fieldset ><br/>
	    <form name='selezupgrade' action='index.php?appname=<?=$appname;?>&op=applicazioni'  method='POST'>
		    <b>Seleziona: </b>	<input type='submit' value='applicazioni' />
	    </form>
	    </fieldset></td><td>

	    <fieldset ><br/>
	    <form name='selezupgrade' action='index.php?appname=<?=$appname;?>&op=blocchi'  method='POST'>
		    <b>Seleziona: </b>	<input type='submit' value='blocchi' />
	    </form>
	    </fieldset></td><td>

	    <fieldset ><br/>
	    <form name='selezupgrade' action='index.php?appname=<?=$appname;?>&op=temi'  method='POST'>
		    <b>Seleziona: </b>	<input type='submit' value='temi' />
	    </form>
	    </fieldset></tr></td><tr><td>

	    <fieldset ><br/>
	    <form name='selezupgrade' action='index.php?appname=<?=$appname;?>&op=extras'  method='POST'>
		    <b>Seleziona: </b>	<input type='submit' value='extras' />
	    </form>
	    </fieldset></td><td>

	    <fieldset ><br/>
	    <form name='selezupgrade' action='index.php?appname=<?=$appname;?>&op=js'  method='POST'>
		    <b>Seleziona: </b>	<input type='submit' value='JS' />
	    </form>
	    </fieldset></td><td>

	    <fieldset ><br/>
	    <form name='selezupgrade' action='index.php?appname=<?=$appname;?>&op=libs'  method='POST'>
		    <b>Seleziona: </b>	<input type='submit' value='librerie' />
	    </form>
	    </fieldset>

	    </td>
	    </tr>
	    </table>

<?

// selezione tramite tabs del da farsi per upgrade --- scelte: tutto - applicazioni - blocchi - temi - extras - js - libs - ecc.

if ($op=='tutto'){
        get_source(".");
        ksort($source);
}

if ($op=='applicazioni'){
        get_source("applications");
        ksort($source);
}

if ($op=='blocchi'){
        get_source("blocks");
        ksort($source);
}

if ($op=='temi'){
        get_source("themes");
        ksort($source);
}

if ($op=='extras'){
        get_source("extras");
        ksort($source);
}

if ($op=='js'){
        get_source("js");
        ksort($source);
}

if ($op=='libs'){
        get_source("libs");
        ksort($source);
}



?>

<h3 class='bartitle'>Check Upgrade</h3>


<?php

if (admin_isadmin()) {
    admin_writelog("admin: logview");

    $i=1;
    if (count($source)){
	foreach($source as $Dpath =>$Spath){
	    $path=dirname($Dpath);
	    if ($Spath!=""){
		echo "<table class='class_table'>\n";
		//echo "<tr><td colspan='3'><hr /></td></tr>";
		echo "<tr><td rowspan='4'><font size='5'>".substr("000".$i++,-3)."</font></td></tr>";
		echo "<tr><td class='firstrow'>File</td> <td class='firstrow'><b>".str_replace("/","/ ", $Dpath)."</b></td></tr>";
		echo "<tr><td class='firstrow'>Source</td><td>".str_replace("/","/ ",$Spath)."</td></tr>";
		echo "<tr><td class='firstrow'>Response</td><td>";

		$response=upgrade_check($Spath,$Dpath);
		switch($response){
		    case 1:
			echo "<a href='index.php?appname=$appname&op=$op&Spath=$Spath&Dpath=$Dpath&upfile=on'>aggiorna ora</a><br />";
			if (($_GET['Spath']==$Spath && $_GET['Dpath']==$Dpath && $_GET['upfile']=='on')|| $_GET['upgrade']=='on'){
			    upgrade_download($Spath,$Dpath);
			    if(substr($Dpath,-11)=="upgrade.inc")include $Dpath;
			}
			break;
		    case 0:
			echo "<a href='index.php?appname=$appname&op=$op&Spath=$Spath&Dpath=$Dpath&upfile=on'>forza aggiornamento</a><br />";
			if ($_GET['Spath']==$Spath && $_GET['Dpath']==$Dpath && $_GET['upfile']=='on'){
			    upgrade_download($Spath,$Dpath);
			    if(substr($Dpath,-11)=="upgrade.inc")include $Dpath;
			}
			break;
		    default:
			echo "<br/>";
			break;
		}
		echo "</td></tr>";
		echo "</table><br/>\n";
	    }
	}
    }
}
?>

<br/>
<h3 class='edit'>
<?php  echo "<a href='index.php?appname=$appname&op=$op&upgrade=on'>aggiorna tutti i pacchetti modificati</a> | "; ?>
<?php  echo "<a href='index.php?appname=$appname&op=$op'>verifica ora </a>"; ?>
</h3>
